<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Quality extends Model
{
    use HasFactory;

    protected $fillable = ['title','project_id','type_id','plan_id','person_id','floor','start_date','end_date','delaies','status'];

    const POSTONLY = ['title','project_id','type_id','plan_id','person_id','floor','start_date','end_date','delaies','status'];

    protected $appends = [
        'status_text'
    ];

    public function getStatusTextAttribute()
    {
        return $this->status ? '有效' : '无效';
    }

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function project()
    {
        return $this->hasOne(Project::class,'id','project_id')->select('id','title','status');
    }

    public function type()
    {
        return $this->hasOne(QualityType::class,'id','type_id')->select('id','title');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','person_id')->select('id','name');
    }
}
